package co.com.services.departamento;

import javax.naming.NamingException;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import co.com.smart.maestro.infraestructure.dto.DepartamentoDTO;
import co.com.smart.session.DelegateContextEJB;

@Path("/SmartDepartamentoService")
public class DepartamentoService {

	@GET
	@Path("/getAllDepartamento")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDepartamentos() throws NamingException {
		return Response.ok(DelegateContextEJB.getDepartamentoBeanLocal().consultarAllDepartamento())
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@POST
	@Path("/getDepartamento")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDepartamento(DepartamentoDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getDepartamentoBeanLocal().consultarDepartamento(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
	@POST
	@Path("/getDepartamentoId")	
	@Produces(MediaType.APPLICATION_JSON)
	public Response getDepartamentoId(DepartamentoDTO json) throws NamingException {
		return Response.ok(DelegateContextEJB.getDepartamentoBeanLocal().consultarDepartamentoId(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/setDepartamento")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setDepartamento( DepartamentoDTO json){ 
		return Response.ok(DelegateContextEJB.getDepartamentoBeanLocal().insertarDepartamento(json))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With")
				.build();
	}

	@PUT
	@Path("/editDepartamento")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setEditDepartamento(DepartamentoDTO json){ 
		return Response.ok(DelegateContextEJB.getDepartamentoBeanLocal().editDepartamento(json))
		.header("Access-Control-Allow-Origin", "*")
		.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
		.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}

	@PUT
	@Path("/removeDepartamento")
	@Consumes(MediaType.APPLICATION_JSON)
	@Produces(MediaType.APPLICATION_JSON)
	public Response setRemoveDepartamento(DepartamentoDTO json){ 
		return Response.ok(DelegateContextEJB.getDepartamentoBeanLocal().removeDepartamento(json, true))
				.header("Access-Control-Allow-Origin", "*")
				.header("Access-Control-Allow-Methods", "POST, GET, PUT, UPDATE, OPTIONS")
				.header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With").build();
	}
	
}
